/* Change the following definition to match the instruction frequency 
of the application in MIPS (MHz) */

#ifndef DELAY_H
#define DELAY_H

#if defined(__dsPIC33E__) || defined(__PIC24E__) 
#ifndef FCY
#define FCY  60000000
#endif
#endif 

#if defined(__dsPIC30F__) || defined(__dsPIC33F__) || defined(__PIC24H__) 
#ifndef FCY
#define FCY  40000000
#endif
#endif 

#define Delay_60nS_Cnt    (unsigned long)(60ULL*(FCY)/1000000000ULL)

#define Delay_150nS_Cnt   (unsigned long)(150ULL*(FCY)/1000000000ULL)
#define Delay_360nS_Cnt   (unsigned long)(360ULL*(FCY)/1000000000ULL)
#define Delay_450nS_Cnt   (unsigned long)(450ULL*(FCY)/1000000000ULL)
#define Delay_600nS_Cnt   (unsigned long)(600ULL*(FCY)/1000000000ULL)
#define Delay_200uS_Cnt   (unsigned long)(200ULL*(FCY)/1000000ULL)
#define Delay_1mS_Cnt     (unsigned long)((FCY)/1000ULL)
#define Delay_2mS_Cnt     (unsigned long)(2ULL*(FCY)/1000000ULL)
#define Delay_5mS_Cnt     (unsigned long)(5ULL*(FCY)/1000000ULL)
#define Delay_15mS_Cnt    (unsigned long)(15ULL*(FCY)/1000000ULL)
#define Delay_1S_Cnt      FCY

#define Delay1S()              __delay32(Delay_1S_Cnt)

/* delays specific to each LCD type */
/* delay btw RS/RW signal to E signal */
#define DelayRSSetupTime()     __delay32(Delay_60nS_Cnt)

/* delay btw E rise and Data available */
#define DelayDBOutput()        __delay32(Delay_360nS_Cnt)
/* min E pulse width low */
#define DelayEPulseWidthLow()  __delay32(Delay_600nS_Cnt)
/* min E pulse width high */
#define DelayEPulseWidthHigh() __delay32(Delay_450nS_Cnt)
/* E pulse cycle time */
#define DelayEPulseWidth()     __delay32(Delay_600nS_Cnt)
/* min Power On Reset time */
#define DelayPORXLCD()         __delay32(Delay_15mS_Cnt)
/* generic delay for LCD */
#define DelayXLCD()            __delay32(Delay_5mS_Cnt)


#endif /*DELAY_H*/